package com.admin.utils;
import com.zmbsms.os.core.util.StringUtils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * ip tools 
 * @author Administrator
 *
 */
public class CookieUtil {

	public static String getCookieUid(HttpServletRequest request) {
		String key="uuid";
		Cookie[] cookies = request.getCookies();
		String resValue = "";
		if (cookies != null && cookies.length > 0) {
			for(int i = 0; i < cookies.length; ++i) {
				if ((key.equalsIgnoreCase(cookies[i].getName()))
						&& org.apache.commons.lang.StringUtils.isNotEmpty(cookies[i].getValue())) {
					resValue = cookies[i].getValue();
				}
			}
		}
		if(StringUtils.isBlank(resValue)){
			resValue = request.getParameter(key);
		}
		if(StringUtils.isBlank(resValue)){
			resValue = request.getHeader("uuid");
		}
		return resValue;
	}
}
